package com.feri.redromance01.service.impl;

import com.feri.redromance01.dao.UserDao;
import com.feri.redromance01.entity.User;
import com.feri.redromance01.service.intf.UserService;
import com.feri.redromance01.util.StringUtil;
import com.feri.redromance01.vo.PageBean;
import com.feri.redromance01.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao dao;


    @Override
    public R save(User user) {
        if (dao.save(user)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R update(User user) {
        if (dao.update(user)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public R delete(int u_id) {
        if (dao.delete(u_id)>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

    @Override
    public PageBean selectPage(String user_act, int page, int limit) {
        if (StringUtil.isNotEmpty(user_act)){
            user_act="%"+user_act+"%";
        }
        int start=(page-1)*limit;

        return PageBean.ok(dao.selectCount(user_act),dao.selectPage(user_act,start,limit));


    }
}
